package com.hhc.repository;

import com.hhc.entity.CourseInfo;
import java.util.List;
import java.util.Optional;

import com.hhc.entity.UserInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * <p>
 *   课程信息表持久化操作接口
 * </p>
 * @author pc
 */
@Repository
public interface CourseInfoRepository extends JpaRepository<CourseInfo, Long> {

    List<CourseInfo> findByStatus(Integer status);

    Page<CourseInfo> findByStatus(Integer status, Pageable pageable);

    boolean existsById(Long id);

    Optional<CourseInfo> findByCourseCode(@Param("courseCode") String courseCode);

    /**
     * 条件模糊查询课程列表（支持分页）
     */
    @Query("SELECT u FROM CourseInfo u WHERE " +
            "(:courseName IS NULL OR u.courseName LIKE %:courseName%) AND " +
            "(:courseCode IS NULL OR u.courseCode LIKE %:courseCode%) AND " +
            "(:credits IS NULL OR u.credits LIKE %:credits%)")
    Page<CourseInfo> findByCondition(
            @Param("courseName") String courseName,
            @Param("courseCode") String courseCode,
            @Param("credits") Integer credits,
            Pageable pageable);

}
